package exercise1;

import java.util.Scanner;

public class No5_29
{
    public boolean runyear(int year)//判断是否是闰年
    {
        if ((year%4==0&&year%100!=0)||year%400!=0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public int days(int year,int month) {
        boolean r_y = runyear(year);
        switch (month) {
            case 1:
                return 31;
            case 2:
                if (r_y) {
                    return 29;
                } else {
                    return 28;
                }
            case 3:
                return 31;
            case 4:
                return 30;
            case 5:
                return 31;
            case 6:
                return 30;
            case 7:
                return 31;
            case 8:
                return 31;
            case 9:
                return 30;
            case 10:
                return 31;
            case 11:
                return 30;
            case 12:
                return 31;
            default:
                return 0;
        }
    }

    public int week(int week,int year,int i)//每个月第一天星期
    {
        if(i==1)
        {
            return week;
        }
        week=(days(year,i-1)%7+week(week,year,i-1))%7;
        return week;
    }

    public int dweek(int day,int week)
    {
        int dweek=(day+week-1)%7;
        return dweek;
    }

    public static void main(String []args)
    {
        No5_29 k=new No5_29();
        Scanner input=new Scanner(System.in);
        System.out.println("输入年： ");
        int year=input.nextInt();
        System.out.println("是星期几呢？ ");
        int week=input.nextInt();

        System.out.println("\t\t\t"+year);
        System.out.println("=============================");
        for(int i=1;i<13;i++)
        {
            System.out.println("\t\t\t"+i+"月"+" "+year+"年");
            System.out.println("———————————————————————————————");
            System.out.println("Sun"+"\t"+"Mon"+"\t"+"Tue\tWed\tThu\tFri\tSat");
            int days=k.days(year,i);
            int weekend=k.week(week,year,i);
            for(int n=0;n<weekend;n++)
            {
                System.out.print(" \t");
            }
            for (int j=1;j<=days;j++)
            {
                System.out.print(j+"\t");
                if(k.dweek(j,weekend)==6)
                {
                    System.out.println();
                }

            }
            System.out.println();
            System.out.println();
        }
    }


}
